import { getPermissions } from '@/api/authorization'

export default {
    namespaced: true,
    state: () => ({
        resources: []
    }),
    mutations: {
        SET_RESOURCES: (state, resources) => {
            state.resources = resources;
        }
    },
    actions: {
        getPermissions({ commit }, accountNo) {
            return new Promise((resolve, reject) => {
                getPermissions(accountNo).then(response => {
                    commit('SET_RESOURCES', [...response]);

                    resolve();
                }).catch(error => {
                    reject(error)
                })
            })
        },
    },
    getters: {
        menus(state) {
            return state.resources.filter(a => a.resourceType == 0);
        }
    }
}